#
# @lc app=leetcode.cn id=20 lang=python3
#
# [20] 有效的括号
#

# @lc code=start
class Solution:
    def isValid(self, s: str) -> bool:
        stack = []
        d = dict({
            '(':')',
            '{':'}',
            '[':']'
        })
        keys = d.keys()
        for ch in s:
            if ch in keys:
                stack.append(ch)
            else:
                if len(stack) == 0:
                    return False
                out_ch = stack.pop()
                if d[out_ch] != ch:
                    return False
        return len(stack) == 0


# @lc code=end

